
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Main Tables"
clear
log using Table7.txt, text replace

***Sales and assets
clear
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data"
use LPSU_MainSample_Sep2024, replace
set matsize 10000
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Tables"

***Set of fixed effects
egen sic1year=group(sic1 year)
qui tabulate sic1year, generate(dsic1year)
egen month_post= group(month post)
qui tabulate month_post, generate(dmonth)
qui tabulate year_around_ipo, generate(deventyear)


***To get the same number of observations in the IV and OLS, we restrict the samples to that of the IV (which drops ids with singletons)
set more off

 
**Sample sales
qui xtivreg2 log_sales_w (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* , fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
gen sample_sales=e(sample)
gen aux_sales=year
replace aux_sales=. if sample_sales==0
bysort id: egen count=count(aux_sales)
replace sample_sales=0 if count<2
drop count aux_sales

***Sample assets
set more off
qui xtivreg2 log_assets_w (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* , fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
gen sample_ass=e(sample)
gen aux_ass=year
replace aux_ass=. if sample_ass==0
bysort id: egen count=count(aux_ass)
replace sample_ass=0 if count<2
drop count aux_ass

***Sample Sales/Assets
set more off
qui xtivreg2 sales_at_w (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* , fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
gen sample_sales_ass=e(sample)
gen aux_saleass=year
replace aux_saleass=. if sample_sales_ass==0
bysort id: egen count=count(aux_saleass)
replace sample_sales_ass=0 if count<2
drop count aux_saleass

** Sales/Emp
set more off
qui xtivreg2 sales_empl_w (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* , fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
gen sample_sales_empl=e(sample)
gen aux_salesemp=year
replace aux_salesemp=. if sample_sales_empl==0
bysort id: egen count=count(aux_salesemp)
replace sample_sales_empl=0 if count<2
drop count aux_salesemp




***Columns 1-3
***Sales
set more off
eststo:qui xtreg log_sales_w IPO deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_sales==1, fe cluster(id) 
outreg2 using Table_com1.xls, keep(IPO) sortvar(IPO IPO_high_self  IPO_small  IPO_Y) tex(frag) excel bdec(3) nocons label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, OLS, Instrument,-) replace

set more off
eststo:qui xtivreg2 log_sales_w (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* if sample_sales==1, fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_com1.xls, keep(IPO) sortvar(IPO IPO_high_self  IPO_small  IPO_Y) tex(frag) excel bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes,Regression, Second stage,Instrument,Pre-IPO ret>0) 

set more off
eststo:qui xtivreg2 log_sales_w (IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self=instrument instrument_fin_dep_eu_hi instrument_small_s instrument_Y  instrument_high_self) ///
 deventyear2 deventyear3 deventyear4 deventyear5   dsic1year* dmonth* if sample_sales==1, fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_com1.xls, keep(IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self ) sortvar(IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self)  tex(frag) excel bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, Second stage,Instrument,Pre-IPO ret>0 & Interactions)  

esttab,   keep(IPO IPO_fin_dep_eu_hi IPO_small_s IPO_Y IPO_high_self) order(IPO IPO_fin_dep_eu_hi IPO_small_s IPO_Y IPO_high_self) ///
 label se b(%9.3f) se(%9.3f) nor2 star(* 0.1 ** 0.05 *** 0.01) addnotes(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Col 1: OLS; Col2 IV; Col 3, IV w interactions) 
 
eststo clear   
 
 
***Columns 4-6 
 **Assets 
 set more off
eststo:qui xtreg log_assets_w IPO deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_ass==1, fe cluster(id) 
outreg2 using Table_com1.xls, keep(IPO) sortvar(IPO IPO_high_self  IPO_small  IPO_Y) tex(frag) excel bdec(3) nocons label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, OLS, Instrument,-) 

set more off
eststo:qui xtivreg2 log_assets_w (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* if sample_ass==1, fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_com1.xls, keep(IPO) sortvar(IPO IPO_high_self  IPO_small  IPO_Y) tex(frag) excel bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes,Regression, Second stage,Instrument,Pre-IPO ret>0) 

set more off
eststo:qui xtivreg2 log_assets_w (IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self=instrument instrument_fin_dep_eu_hi instrument_small_s instrument_Y  instrument_high_self) ///
 deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_ass==1, fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_com1.xls, keep(IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self ) sortvar(IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self)  tex(frag) excel bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, Second stage,Instrument,Pre-IPO ret>0 & Interactions)   
 
esttab,   keep(IPO IPO_fin_dep_eu_hi IPO_small_s IPO_Y IPO_high_self) order(IPO IPO_fin_dep_eu_hi IPO_small_s IPO_Y IPO_high_self) ///
 label se b(%9.3f) se(%9.3f) nor2 star(* 0.1 ** 0.05 *** 0.01) addnotes(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Col 1: OLS; Col2 IV; Col 3, IV w interactions) 
 
eststo clear   
 
***Columns 7-9  
 **Sales/ass
 set more off
eststo:qui xtreg sales_at_w IPO deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_sales_ass==1, fe cluster(id) 
outreg2 using Table_com1b.xls, keep(IPO) sortvar(IPO IPO_high_self  IPO_small  IPO_Y) tex(frag) excel bdec(3) nocons label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, OLS, Instrument,-) replace

set more off
eststo:qui xtivreg2 sales_at_w (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* if sample_sales_ass==1, fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_com1b.xls, keep(IPO) sortvar(IPO IPO_high_self  IPO_small  IPO_Y) tex(frag) excel bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes,Regression, Second stage,Instrument,Pre-IPO ret>0) 

set more off
eststo:qui xtivreg2 sales_at_w (IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self=instrument instrument_fin_dep_eu_hi instrument_small_s instrument_Y  instrument_high_self) ///
 deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_sales_ass==1, fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_com1b.xls, keep(IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self ) sortvar(IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self) tex(frag) excel bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, Second stage,Instrument,Pre-IPO ret>0 & Interactions)  

esttab,   keep(IPO IPO_fin_dep_eu_hi IPO_small_s IPO_Y IPO_high_self) order(IPO IPO_fin_dep_eu_hi IPO_small_s IPO_Y IPO_high_self) ///
 label se b(%9.3f) se(%9.3f) nor2 star(* 0.1 ** 0.05 *** 0.01) addnotes(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Col 1: OLS; Col2 IV; Col 3, IV w interactions) 
 
eststo clear  
 
 
***Columns 10-12   
 **Sales/empl 
 set more off
eststo:qui xtreg sales_empl_w IPO deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_sales_empl==1, fe cluster(id) 
outreg2 using Table_com1b.xls, keep(IPO) sortvar(IPO IPO_high_self  IPO_small  IPO_Y) tex(frag) excel bdec(3) nocons label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, OLS, Instrument,-) 

set more off
eststo:qui xtivreg2 sales_empl_w (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* if sample_sales_empl==1, fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_com1b.xls, keep(IPO) sortvar(IPO IPO_high_self  IPO_small  IPO_Y) tex(frag) excel bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes,Regression, Second stage,Instrument,Pre-IPO ret>0) 

set more off
eststo:qui xtivreg2 sales_empl_w (IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self=instrument instrument_fin_dep_eu_hi instrument_small_s instrument_Y  instrument_high_self) ///
 deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_sales_empl==1, fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_com1b.xls, keep(IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self ) sortvar(IPO IPO_fin_dep_eu_hi   IPO_small_s IPO_Y IPO_high_self) tex(frag) excel bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, Second stage,Instrument,Pre-IPO ret>0 & Interactions)   
 
esttab,   keep(IPO IPO_fin_dep_eu_hi IPO_small_s IPO_Y IPO_high_self) order(IPO IPO_fin_dep_eu_hi IPO_small_s IPO_Y IPO_high_self) ///
 label se b(%9.3f) se(%9.3f) nor2 star(* 0.1 ** 0.05 *** 0.01) addnotes(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Col 1: OLS; Col2 IV; Col 3, IV w interactions) 
 
eststo clear  
 
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Main Tables"
log close 
  
 
